#求循环节
def length(n):
    i = 1
    while n % 2 == 0:
        n = n//2
    while n % 5 == 0:
        n = n//5
    while True:
        if (10**i - 1) % n == 0:
            return i
        else:
            i += 1

num, l_max = 7,6
for n in range(2,1000):
    if l_max < length(n):
        num,l_max = n,length(n)

print(f"{num}对应的循环节长度为{l_max}")

import collections
def function(a,b):
    index = 0
    d = collections.defaultdict(int)
    while True:
        remainder = a%b
        if not remainder:
            print(index,0)
            break
        else:
            index += 1
            if not d[remainder]:
                d[remainder] = index
                a = remainder * 10
            else:
                print(d[remainder]-1,index-d[remainder])
                break
a = function(2,1000)
